var app = getApp()  
Page({  
  data: {  
    navbar: ['闲置', '图书'],  
    currentTab: 0,
    index:0,
    list:[],
    pagenum:1
  },  
  navbarTap: function(e){  
    this.setData({  
      currentTab: e.currentTarget.dataset.idx,
      list:[],
      pagenum:1
    })  
    this.getDataList();
  },
  onLoad:function(e){
    var that = this;
  },
  onShow:function(e){
    var that = this;
    this.setData({
      currentTab:1
    })
    this.getDataList();
  },
  bindPickerChange:function(e){
    var that = this;
    that.setData({  
      index:e.detail.value
    })
  },
  getDataList:function(e){
    var that = this;
        wx.request({
            url: app.data.server+'/index.php/Tongcheng/Book/getShouCangList?type='+that.data.currentTab+'&pagenum='+that.data.pagenum+'&uid='+getApp().globalData.userInfo.uid,
            success:function(d){
                // console.log('123'+JSON.stringify(d.data));
                if(0 == d.data){
                    return;
                }
                that.setData({
                    list:d.data
                })
            }
        })
      },
  showXianZhiInfo:function(e){
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url:'/pages/index/xianzhiinfo?id='+id
    })
  },
  showBookInfo:function(e){
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url:'/pages/find/bookinfo2_info?id='+id
    })
  },
    quxiaoshoucang:function(e){
    var that = this;
      var id = e.currentTarget.dataset.id;
        wx.showModal({
            title:'提示',
            content:'确定取消收藏吗？',
            showCancel:true,
            success:function(res){
                if (res.confirm) {
                wx.request({
                    url:app.data.server+'/index.php/Tongcheng/Book/quXiaoShouCang?id='+id,
                    success:res=>{
                        if(0 == res.data){
                            wx.showToast({
                                title:'取消收藏失败',
                                icon: 'success',
                                duration: 2000
                            })
                        }else{
                            wx.showToast({
                                title:'取消收藏成功',
                                icon: 'success',
                                duration: 2000
                            })
                        }
                        setTimeout(function(){
                            that.setData({
                                list:[],
                                pagenum:1
                            })
                            that.getDataList();
                        },1000)
                    }
                })
              }
            }
        })
  }

})